<?php

require_once "OPDatabase.php";

class Poster {
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Const
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Poster width
	*/
	const WIDTH = 100;
	
	/**
	 * Poster height
	 */
	const HEIGHT = 100;
	
	/**
	* Wall height
	*/
	const WALL_WIDTH = 500;
	
	/**
	* Wall height
	*/
	const WALL_HEIGHT = 500;
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Attributes
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Id of the poster
	 * 
	 * @var int
	 */
	protected $id = null;
	
	/**
	* X of the poster
	*
	* @var int
	*/
	public $x;
	
	/**
	* Y of the poster
	*
	* @var int
	*/
	public $y;
	
	/**
	* Team of the poster
	*
	* @var int
	*/
	public $team;
	
	/**
	* File name of the poster
	*
	* @var string
	*/
	public $fileName;
	
	/**
	* DateTime of the poster
	*
	* @var date
	*/
	protected $dateTime;
	
	/**
	 * -------------------------------------------------------------------------
	 * 
	 * 									Static
	 * 
	 * -------------------------------------------------------------------------
	 */
	
	/**
	* -------------------------------------------------------------------------
	* 									Constructeur
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Static constructor creating a new Poster with a x, y ,team, datetime, file name and occupation
	*
	* @param $x, $y, $team
	* @return Poster
	*/
	public static function newWithXYTeamAndFileName($x, $y, $team, $fileName){		
		$newPoster	= new Poster();
				
		$newPoster	->setX($x)
					->setY($y)
					->setTeam($team)
					->setFileName($fileName)
					->setDateTime(date('Y-m-d H:i:s'));		
		return $newPoster;	
	
	}
	
	/**
	* Static constructor creating a new Poster with a x, y , team and datetime
	*
	* @param $id, $x, $y, $team, $occupation
	* @return Poster
	*/
	public static function newWithIdXYTeamAndFileName($id, $x, $y, $team, $fileName){
		$newPoster	= self::newWithXYTeamAndFileName($x, $y, $team, $fileName);
		$newPoster	->setId($id);
	
		return $newPoster;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Get the poster corresponding to the x and y position in the database
	 * 
	 * @param $x, $y
	 * @return Poster
	 */
	public static function getPoster($x, $y) {
		return OPDatabase::getPoster($x, $y);
		
	}
	
	/**
	 * Get all the posters after the specified dateTime
	 * 
	 * @param $dateTime
	 * @return array<Poster>
	 */
	public static function getPostersAfter($dateTime) {
		return OPDatabase::getPostersAfter($dateTime);
		
	}
	
	/**
	* Get all the posters after the specified dateTime for JSon
	*
	* @param $dateTime
	* @return array<Poster>
	*/
	public static function getPostersForJSonAfter($dateTime) {
		echo json_encode(self::getPostersAfter($dateTime));
	
	}
	
	/**
	 * Get all the posters ordered by date time
	 * 
	 * @return array<Poster>
	 */
	public static function allPosters() {
		return OPDatabase::allPosters();
		
	}
	
	/**
	 * Get all the posters for JSon
	 * 
	 * @return json array
	 */
	public static function allPostersForJSon() {
		echo json_encode(self::allPosters());
		
	}
	
	/**
	* -------------------------------------------------------------------------
	* 								Occupation Calcul
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Calculates occupation for the specified team
	 * 
	 * @param $team
	 * @return percentage
	 */
	public static function occupationForTeam($team) {
		return OPDatabase::occupationForTeam($team);
		
	}
	
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Dynamic
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	* -------------------------------------------------------------------------
	* 									Setters
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Set poster's id
	*
	* @param $id
	* @return Poster
	*/
	public function setId($id) {
		$this->id = $id;
	
		return $this;
	
	}
	
	/**
	* Set poster's X
	*
	* @param $x
	* @return Poster
	*/
	public function setX($x) {
		$this->x = $x;
		
		return $this;
	
	}
	
	/**
	* Set poster's Y
	*
	* @param $y
	* @return Poster
	*/
	public function setY($y) {
		$this->y = $y;
	
		return $this;
	
	}
	
	/**
	* Set poster's team
	*
	* @param $team
	* @return Poster
	*/
	public function setTeam($team) {
		$this->team = $team;
	
		return $this;
	
	}
	
	/**
	* Set poster's file name
	*
	* @param $fileName
	* @return Poster
	*/
	public function setFileName($fileName) {
		$this->fileName = $fileName;
	
		return $this;
	
	}
	
	/**
	* Set poster's date time
	*
	* @param $dateTime
	* @return Poster
	*/
	public function setDateTime($dateTime) {
		$this->dateTime = $dateTime;
	
		return $this;
	
	}

	
	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Return the id of the poster
	 * 
	 * @return int
	 */
	public function id() {
		return $this->id;
		
	}
	
	/**
	* Return the X of the poster
	*
	* @return int
	*/
	public function x() {
		return $this->x;
	
	}
	
	/**
	* Return the Y of the poster
	*
	* @return int
	*/
	public function y() {
		return $this->y;
	
	}
	
	/**
	* Return the team of the poster
	*
	* @return int
	*/
	public function team() {
		return $this->team;
	
	}
	
	/**
	* Return the file name of the poster
	*
	* @return string
	*/
	public function fileName() {
		return $this->fileName;
	
	}
	
	/**
	* Return the date time of the poster
	*
	* @return datetime
	*/
	public function dateTime() {
		return $this->dateTime;
	
	}
	

	
	/**
	* -------------------------------------------------------------------------
	* 									Database
	* -------------------------------------------------------------------------
	*/
	
	public function save() {
		OPDatabase::savePoster($this);
		OPDatabase::savePostersPixels($this);
	
	}
	
}